<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 2017/9/29
 * Time: 8:18
 */

class Person
{
    public $name;
    public  $age;
    public $sex;

    public function __set($name, $value)
    {
        if ($name='age'){
            $this->age=(($value<0)?1:$value);
        }

    }

    public function __construct($name,$age,$sex){
        $this -> name=$name;
        $this->age=$age;
        $this->sex=$sex;
        $this->say();
    }

    public function say(){
        echo  "我的名字是 :{$this->name},我的年龄是{$this->age},我的性别:{$this->sex}";
    }
}

$p1 = new Person();
$p1->__construct("张三",18,'男');